package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.FoodService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/admin/dish")
public class FoodController {
    @Autowired
    private FoodService foodService;
    //新增菜品
    @PostMapping
    public Result addFood(@RequestBody DishDTO dishDTO){
        foodService.addFood(dishDTO);
        return Result.success();
    }
   //菜品分页查询
    @GetMapping("/page")
    public Result selectFood(DishPageQueryDTO dishPageQueryDTO){
        PageResult pageResult = foodService.selectFood(dishPageQueryDTO);
        return Result.success(pageResult);
    }
    //菜品批量删除
    @DeleteMapping
    public Result deleteFood(@RequestParam List<Long> ids){
        foodService.deleteFood(ids);
        return Result.success();
    }
    //根据id查询菜品(修改前的数据回显)
    @GetMapping("/{id}")
    public Result selectById(@PathVariable Long id){
        DishDTO dishDTO = foodService.selectById(id);
        return Result.success(dishDTO);
    }
    //修改菜品
    @PutMapping
    @ApiOperation("修改菜品")
    public Result update(@RequestBody DishDTO dishDTO) {
        foodService.updateWithFlavor(dishDTO);
        return Result.success();
    }
    //修改菜品其售卖状态
    @PostMapping("status/{status}")
    public Result putStatus(@PathVariable Integer status,Integer id){
        foodService.putStatus(status,id);
        return Result.success();
    }
    //根据分类查询
    @GetMapping("/list")
    public Result selectCategory(Long categoryId){
        List<Dish> dishes = foodService.selectCategory(categoryId);
        return Result.success(dishes);
    }

}
